import sqlite3

j = 0
device_counter = {}
conn = sqlite3.connect('../database.db')
conn.row_factory = sqlite3.Row
with open('device_counter', 'w', encoding='utf8') as f:
    for i in range(1262, 1263):
        with open('temp{}'.format(i), 'w', encoding='utf8') as temp:
            sql = 'select device from gate_pass_info_{}'.format(i)
            result = conn.execute(sql).fetchall()
            for row in result:
                data = tuple(row)
                device = data[0]
                temp.write('{}\n'.format(device))
        #     if device not in device_counter:
        #         device_counter[device] = 0
        #     device_counter[device] += 1
        temp.close()
        print('gate_pass_info_{} finish'.format(i))

print('finish read, start write')
with open('device_counter', 'w', encoding='utf8') as f:
    for device, count in device_counter.items():
        line = '{}={}\n'.format(device, count)
        f.write(line)
print('finish write')
